package com.fh.shop.admin.controller.brand;

import com.fh.shop.admin.annotation.LogInfo;
import com.fh.shop.admin.biz.brand.IBrandService;
import com.fh.shop.admin.common.ServerResponse;
import com.fh.shop.admin.controller.FilePathController;
import com.fh.shop.admin.po.brand.Brand;
import com.fh.shop.admin.common.DataTableResult;
import com.fh.shop.admin.param.brand.BrandQueryParam;
import com.fh.shop.admin.param.brand.BrandUpdateParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/brand")
public class BrandController extends FilePathController {
    @Resource(name = "brandService")
    private IBrandService brandService;
    @Resource
    private HttpServletRequest request;

    private static final Logger LOGGER = LoggerFactory.getLogger(BrandController.class);

    @GetMapping("/toIndex")
    public String toIndex(){
        return "brand/index";
    }
    //增加
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ResponseBody
    @LogInfo(info = "增加品牌")
    public ServerResponse add(Brand brand) {
        return brandService.addBrand(brand);
    }

    //列表展示
    @RequestMapping(value = "/list",method = RequestMethod.POST)
    public @ResponseBody DataTableResult list(BrandQueryParam brandQueryParam){
        LOGGER.info("控制层——品牌列表展示");
        return brandService.findBrandlist(brandQueryParam);
    }
    //回显
    @RequestMapping(value = "/findBrand",method = RequestMethod.POST)
    public @ResponseBody ServerResponse findBrand(Long id){
        return brandService.findBrand(id);
    }

    //修改
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @LogInfo(info = "修改品牌")
    public @ResponseBody ServerResponse update(BrandUpdateParam brandUpdateParam){
        return brandService.editBrand(brandUpdateParam,getRealPath(request,"/"));
    }

    //删除
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @LogInfo(info = "删除品牌")
    public @ResponseBody ServerResponse delete(Long id){
        return brandService.deleteBrand(id,getRealPath(request,"/"));
    }

    //批量删除
    @RequestMapping(value = "/deleteBatch",method = RequestMethod.POST)
    @LogInfo(info = "批量删除品牌")
    public @ResponseBody ServerResponse deleteBatch(String ids){
        return brandService.deleteBatchBrand(ids,getRealPath(request,"/"));
    }

    //查询所有品牌
    @PostMapping("findBrandList")
    @ResponseBody
    public ServerResponse findBrandList(){
        return brandService.findBrandList();
    }
}
